<template>
    <van-config-provider :theme-vars="themeVars">
        <van-button type="danger" size="mini" round @click="handleAdd">
            <van-icon name="cart" size="20" />
        </van-button>
    </van-config-provider>
</template>

<script setup>
import useCartStore from '../../store/cart';
import 'vant/es/toast/style';
import { ref } from 'vue';
import { Toast } from 'vant';
const store = useCartStore()
const props = defineProps(['item'])
const themeVars = {
    toastMaxWidth: "100%",
    toastIconSize: "30px",
    toastDefaultMinHeight: "30%",
}
const handleAdd = () => {
    console.log(props.item)
    const { id, image, title, price } = props.item
    store.cartItem = {
        id, image, title, price,
        count:store.cartItem.count,
        check:store.cartItem.check
    }
    if (store.cart.findIndex(arr => arr.id === id) === -1) {
        store.totalAmount += 1
        store.cart.push(store.cartItem)
        console.log(store.cart)
    } else {
        store.cart[store.cart.findIndex(arr => arr.id === id)].count += 1
        console.log(store.cart)
    }
    
    console.log(store.totalAmount)
    console.log(store.totalMoney)
    Toast.success('加入购物车\n成功');
    // console.log('加入购物车')
}
</script>

<style lang="less" scoped>

</style>
 